<!-- login.html -->
<!DOCTYPE html>
<html>
<head>
    <title>Login</title>
</head>
<body>
    <h1>Login</h1>
    <form id="loginForm">
        <input type="text" name="login_name" placeholder="Username" required>
        <input type="password" name="passwd" placeholder="Password" required>
        <button type="submit">Login</button>
    </form>
    <script>
        document.getElementById('loginForm').onsubmit = async (e) => {
            e.preventDefault();
            const formData = new FormData(e.target);
            console.log(Object.fromEntries(formData));
            const response = await fetch('/users/login', {
            method: 'POST',
            body: JSON.stringify(Object.fromEntries(formData)),
            headers: { 'Content-Type': 'application/json' }
        });

        if (!response.ok) {
            const errorText = await response.text();
            console.error('Error response:', errorText);
            return;
        }

        const result = await response.json();
        alert(result.msg);
        };
    </script>
</body>
</html>